const app = getApp()
import{getUrl}from "../../../utils/url";
let _this;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showFee:'0.00',
    realFee:0,
    cashFee:null,
    zfb:''
  },
  cashInput(e){
    if(e.detail.value > 1000){
      wx.showToast({
        title: '单笔提现金额不能大于1000元',
        icon: 'none'
      })
    } else{
      this.setData({
        cashFee: e.detail.value
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _this = this
    this.getData(),
    this.setData({
      zfb:wx.getStorageSync('user').zfb
    })
  },
  getData(){
   let user= wx.getStorageSync('user');
    wx.request({
      url: getUrl()+`/user/info/${user.id}`,  //路径
      success: function(res) {
        wx.setStorageSync('user', res.data)
        _this.setData({
         showFee:res.data.showFee
        }) 
      }
    })
  },

  cashAll(){
    if(this.data.showFee > 0.3){
      this.setData({
        cashFee:_this.data.showFee
      })
    }else{
      wx.showToast({
        title: '单笔提现金额不能小于0.3元',
        icon: 'none'
      })
    }
  },
  cashIt(){
    if (this.data.cashFee <=0.3){
      wx.showToast({
        title: '单笔提现金额不能小于0.3元',
        icon:'none'
      })
    } else if (this.data.cashFee >1000){
      wx.showToast({
        title: '单笔提现金额不能大于1000元',
        icon: 'none'
      })
    } else if (this.data.cashFee > this.data.showFee+0.01) {
      wx.showToast({
        title: '提现金额不能大于余额',
        icon: 'none'
      })
      this.setData({
        cashFee: this.data.showFee.toFixed(2)
      })
    }else{
      wx.showLoading({
        title: '请求中',
        task:true
      })
    let user=  wx.getStorageSync('user');
       user.showFee=user.showFee-this.data.cashFee;
     let users={}
     users.id=user.id;
     users.showFee=user.showFee; 
    wx.request({
        url: getUrl()+`/user/update`,  //路径
        data:users,//参数
        success: function(res) {
          wx.hideLoading()
          wx.showModal({
            title: '提现结果',
            content: "审核中",
            showCancel:false,
          })
          _this.getData()
        }
      })  
      
    }
  }
})